Dynamically generated URL could not be opened in FireFox
-
* I have a code that generate form dynamically (form on a webpage is generated through code). The action attribute is set to 'TestMyPage.ashx'. When run, this URL is opened successfully in IE. * But when same value ('TestMyPage.ashx') is set for action attribute for FireFox, it do not load the said page. * When checked, for FireFox it loads the page only when it is prefixed with protocol, host and virtual directory information, like "protocol://localdomain/virtualdirectory/pagename.ashx" Example: "http://localhost:8795/myapp/TestMyPage.ashx" This url is successfully loaded by FireFox. But I don't want to set those prefixes (protocol, host, virtual dir.) myself. When searched on, it found that FireFox should also behave like IE in this case. So I could not guess what is the problem for such behaviour in my application (Is it because the form is generated dynamically?..) Any suggestion is welcome... Thank you.
Ashish Software Engineer, Pune
-
* I have a code that generate form dynamically (form on a webpage is generated through code). The action attribute is set to 'TestMyPage.ashx'. When run, this URL is opened successfully in IE. * But when same value ('TestMyPage.ashx') is set for action attribute for FireFox, it do not load the said page. * When checked, for FireFox it loads the page only when it is prefixed with protocol, host and virtual directory information, like "protocol://localdomain/virtualdirectory/pagename.ashx" Example: "http://localhost:8795/myapp/TestMyPage.ashx" This url is successfully loaded by FireFox. But I don't want to set those prefixes (protocol, host, virtual dir.) myself. When searched on, it found that FireFox should also behave like IE in this case. So I could not guess what is the problem for such behaviour in my application (Is it because the form is generated dynamically?..) Any suggestion is welcome... Thank you.
Ashish Software Engineer, Pune
What's wrong with prepending the http prefix?
-
What's wrong with prepending the http prefix?
-
I was addressing this comment in particular:
But I don't want to set those prefixes (protocol, host, virtual dir.) myself.
I'm just suggesting that you should set them yourself to get around the issue. -
I was addressing this comment in particular:
But I don't want to set those prefixes (protocol, host, virtual dir.) myself.
I'm just suggesting that you should set them yourself to get around the issue. -
Below is the code for the same I am finding the solution. -----------------------------------
if( isIE ) //Execute for Internet Explorer. { var \_form = this.innerDocument.createElement('<form id = "UPLOADMYPAGE" method="post" enctype="multipart/form-data" action="TestMyPage.ashx" />'); //The action attribute for IE requires to be pagename only. IE loads it properly. var formHTML = \_form.outerHTML; document.getElementById('MYFRAME').contentWindow.document.body.innerHTML = formHTML; } else //Execute for FireFox. { var protocol = document.location.protocol; var host = document.location.host; var \_form = document.createElement('form'); this.innerDocument.body.appendChild(\_form); \_form.id = 'UPLOADMYPAGE'; \_form.name = 'UPLOADMYPAGE'; \_form.method = 'post'; \_form.enctype = 'multipart/form-data'; \_form.action = protocol + '//' + host + virtualDirectoryName + '/TestMyPage.ashx'; //The action attribute for FireFox requires to be prefixed with protocol, host and vir. dir. name to create url. Then only FireFox loads it properly, otherwise it could not load the page. } document.getElementById('MYFRAME').contentWindow.document.getElementById('UPLOADMYPAGE').submit();
------------------------------------------- //This is requirement from Code Testing Team. So I have to make it possible without using prefixes. //Please suggest how can this code be modified to provide only page name for action attribute in FireFox as in case of IE. I would like to know why FireFox is not doing it (as I have came to know that FireFox loads as that of IE).
Ashish Software Engineer, Pune
-
Below is the code for the same I am finding the solution. -----------------------------------
if( isIE ) //Execute for Internet Explorer. { var \_form = this.innerDocument.createElement('<form id = "UPLOADMYPAGE" method="post" enctype="multipart/form-data" action="TestMyPage.ashx" />'); //The action attribute for IE requires to be pagename only. IE loads it properly. var formHTML = \_form.outerHTML; document.getElementById('MYFRAME').contentWindow.document.body.innerHTML = formHTML; } else //Execute for FireFox. { var protocol = document.location.protocol; var host = document.location.host; var \_form = document.createElement('form'); this.innerDocument.body.appendChild(\_form); \_form.id = 'UPLOADMYPAGE'; \_form.name = 'UPLOADMYPAGE'; \_form.method = 'post'; \_form.enctype = 'multipart/form-data'; \_form.action = protocol + '//' + host + virtualDirectoryName + '/TestMyPage.ashx'; //The action attribute for FireFox requires to be prefixed with protocol, host and vir. dir. name to create url. Then only FireFox loads it properly, otherwise it could not load the page. } document.getElementById('MYFRAME').contentWindow.document.getElementById('UPLOADMYPAGE').submit();
------------------------------------------- //This is requirement from Code Testing Team. So I have to make it possible without using prefixes. //Please suggest how can this code be modified to provide only page name for action attribute in FireFox as in case of IE. I would like to know why FireFox is not doing it (as I have came to know that FireFox loads as that of IE).
Ashish Software Engineer, Pune
Same code as above reply is posted again since comments added by me were not viewable (sorry for inconvenience). -------------------------------------------
if( isIE ) //Execute for Internet Explorer. { var \_form = this.innerDocument.createElement('<form id = "UPLOADMYPAGE" method="post" enctype="multipart/form-data" action="TestMyPage.ashx" />'); //The above action attribute for IE requires to be pagename only. //IE loads it properly. var formHTML = \_form.outerHTML; document.getElementById('MYFRAME').contentWindow.document.body.innerHTML = formHTML; } else //Execute for FireFox. { var protocol = document.location.protocol; var host = document.location.host; var \_form = document.createElement('form'); this.innerDocument.body.appendChild(\_form); \_form.id = 'UPLOADMYPAGE'; \_form.name = 'UPLOADMYPAGE'; \_form.method = 'post'; \_form.enctype = 'multipart/form-data'; \_form.action = protocol + '//' + host + virtualDirectoryName + '/TestMyPage.ashx'; //The above action attribute for FireFox requires to be prefixed //with protocol, host and vir. dir. name to create url. Then only //FireFox loads it properly, otherwise it could not load the page. } document.getElementById('MYFRAME').contentWindow.document.getElementById('UPLOADMYPAGE').submit();
------------------------------------------- //This is requirement from Code Testing Team. So I have to make it possible without using prefixes. //Please suggest how can this code be modified to provide only page name for action attribute in FireFox as in case of IE. I would like to know why FireFox is not doing it (as I have came to know that FireFox loads as that of IE).
Ashish Software Engineer, Pune
-
Same code as above reply is posted again since comments added by me were not viewable (sorry for inconvenience). -------------------------------------------
if( isIE ) //Execute for Internet Explorer. { var \_form = this.innerDocument.createElement('<form id = "UPLOADMYPAGE" method="post" enctype="multipart/form-data" action="TestMyPage.ashx" />'); //The above action attribute for IE requires to be pagename only. //IE loads it properly. var formHTML = \_form.outerHTML; document.getElementById('MYFRAME').contentWindow.document.body.innerHTML = formHTML; } else //Execute for FireFox. { var protocol = document.location.protocol; var host = document.location.host; var \_form = document.createElement('form'); this.innerDocument.body.appendChild(\_form); \_form.id = 'UPLOADMYPAGE'; \_form.name = 'UPLOADMYPAGE'; \_form.method = 'post'; \_form.enctype = 'multipart/form-data'; \_form.action = protocol + '//' + host + virtualDirectoryName + '/TestMyPage.ashx'; //The above action attribute for FireFox requires to be prefixed //with protocol, host and vir. dir. name to create url. Then only //FireFox loads it properly, otherwise it could not load the page. } document.getElementById('MYFRAME').contentWindow.document.getElementById('UPLOADMYPAGE').submit();
------------------------------------------- //This is requirement from Code Testing Team. So I have to make it possible without using prefixes. //Please suggest how can this code be modified to provide only page name for action attribute in FireFox as in case of IE. I would like to know why FireFox is not doing it (as I have came to know that FireFox loads as that of IE).
Ashish Software Engineer, Pune
When I tried using below code it correctly worked. FireFox opened webpage mentioned in action attribute (page name without protocol, domain and virtual directory).
var f1 = document.createElement("form");
f1.id = 'MYFORM';
f1.name = 'MYFORM';
f1.method = 'post';
f1.action="TestPage.aspx";
alert(f1.action); //This shows complete url of page instead of only page name, as expected - correct.
this.document.body.appendChild(f1);
f1.submit();I could not guess why in my main application's code (posted before this post) is not showing complete url when "alert" is done. In that it shows only the page name and not the complete url. Can anyone guess what might be the reason for this... Thank you.
Ashish Software Engineer, Pune
-
* I have a code that generate form dynamically (form on a webpage is generated through code). The action attribute is set to 'TestMyPage.ashx'. When run, this URL is opened successfully in IE. * But when same value ('TestMyPage.ashx') is set for action attribute for FireFox, it do not load the said page. * When checked, for FireFox it loads the page only when it is prefixed with protocol, host and virtual directory information, like "protocol://localdomain/virtualdirectory/pagename.ashx" Example: "http://localhost:8795/myapp/TestMyPage.ashx" This url is successfully loaded by FireFox. But I don't want to set those prefixes (protocol, host, virtual dir.) myself. When searched on, it found that FireFox should also behave like IE in this case. So I could not guess what is the problem for such behaviour in my application (Is it because the form is generated dynamically?..) Any suggestion is welcome... Thank you.
Ashish Software Engineer, Pune
i had executed your code it has problem as you explained. i think you must document.createDocumentFragment('<form...)>it should work....if you get any problem or explanation then please reply me createElement--for IE createDocumentFragment-for Fire Fox
Anshuman Singh