[removed] inside javascript code [removed]()

前端 未结 5 836
忘掉有多难
忘掉有多难 2020-12-31 17:53

I got a portion of javascript code embedded in HTML (generated on the server side) that looks like this:

function winWriteMail2(){
  var win = open(\'\',\'wi         


        
5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-31 18:52

    i know this is a 4 y/o thread, but I wanted to add a fix I just combined via a few different articles/questions:

    rather than appending the documents (.css, .js, etc) after the document.write call, I altered my open call to look like:

    var win = window.open("//"+document.domain, "_blank");//document.domain is the fix
    if(win != null)
        win.document.write('...');//insert your content, wherever you got it (hand-coded, ajax, etc)
    

    adding '//' will automatically set the protocol (http vs https) and document.domain = well, your domain. essentially, this sets the address bar correctly in IE so that using /foo/bar.js type src's and href's will be located and work correctly.

    hope this helps someone! :P

提交回复
热议问题