Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Why writing <embed> tag by JS does not work ?

    I have a piece of code which I suppose to click on to activate:

    Code:
    <a href ="javascript:(function()
    {
    		newwindow = window.open();
    		newwindow.document.write('<html><head><title>Your new title here</title></head>');
    		newwindow.document.write('<body><embed src = 'http://www.flashppt.com/images/tangramone.swf'  height='100%' width='100%'></embed></body></html>');
    		
    		}
    		)();"> Run flash popup </a>
    I have spent a very long time looking at it but I still can't figure it out. The problem is with line with <embed> tag.
    My purpose is to open a swf flash in a new popup window such that it must have a Pretty title name (instead of its addresss). Since opening that SWF directly does not leave me the option of change the popup title , so I use the above method...

    I appreciate much if you can help !

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,355
    Thanks
    11
    Thanked 558 Times in 551 Posts
    If you want to use quotes inside quotes you'll have to do one of the following

    1. Use different quote styles for the outer and inner quotes OR
    2. Escape the inner quotes

    Example for 1
    Code:
    newwindow.document.write('<body><embed src = "http://www.flashppt.com/images/tangramone.swf"  height="100%" width="100%"></embed></body></html>');
    Example for 2
    Code:
    newwindow.document.write("<body><embed src = \"http://www.flashppt.com/images/tangramone.swf\"  height=\"100%\" width=\"100%\"></embed></body></html>");
    Otherwise each inner quote will be interpreted as a closing outer quote.

  • Users who have thanked devnull69 for this post:

    poptart (07-25-2011)

  • #3
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    devnul69, Thank you for your suggestion,
    However,
    Example 1 and 2 does not work since the double quotes surrounding the url pairs up with the double quote in the Javascript function declaration.

    After a little change in Example 2, what I don't understand why this piece of code is still not valid:
    Code:
    <a href ="javascript:(function()
    {
    		newwindow = window.open();
    		newwindow.document.write('<html><head><title>Your new title here</title></head>');
    		newwindow.document.write('<body><embed src = \"http://www.flashppt.com/images/tangramone.swf\"  height=\"100%\" width=\"100%\"></embed></body></html>');
    		
    		}
    		)();"> Run flash popup </a>

    However, instead of escaping all the double quote, we escape all the single quote. This seems to be working:
    Code:
    <a href ="javascript:(function()
    {
    		newwindow = window.open();
    		newwindow.document.write('<html><head><title>Your new title here</title></head>');
    		newwindow.document.write('<body><embed src = \'http://www.flashppt.com/images/tangramone.swf\'  height=\'100%\' width=\'100%\'></embed></body></html>');
    		
    		}
    		)();"> Run flash popup </a>
    Can you share some insights ?

  • #4
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,355
    Thanks
    11
    Thanked 558 Times in 551 Posts
    The escaping is used in Javascript and not HTML ... this is why your first example is not working since you tried to escape the double quotes on HTML level.

    Your second example escapes the single quotes on javascript level whereas the outer quotes are double quotes and don't interfere with any (HTML) inner quotes.

  • #5
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Right, thanks a lot. I think I got a hang on this now, I am still learning JS.
    I used to use double quotes for string const, now I may have to give pref first to single quote , second to escape single quote, lastly double quotes...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •