...

View Full Version : Why writing <embed> tag by JS does not work ?



poptart
07-24-2011, 12:04 PM
I have a piece of code which I suppose to click on to activate:



<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 !

devnull69
07-24-2011, 01:38 PM
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


newwindow.document.write('<body><embed src = "http://www.flashppt.com/images/tangramone.swf" height="100%" width="100%"></embed></body></html>');


Example for 2


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.

poptart
07-25-2011, 08:23 AM
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:



<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:


<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 ?

devnull69
07-25-2011, 09:57 AM
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.

poptart
07-26-2011, 10:30 AM
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...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum