开发者

Javascript reads previously opening tab html on the save Window

I have a task that i do not know where to start, i hope Stack Overflowers can give me some ideas.

I want to read the html source code of the previously opened and still opening tab in my web page. My approach was to grab the url of the targeted page, send that url to server and do something, then use it in my web page. But i am facing the "same domain policy" on the server side, i know that JSONP can be used, but i must use POST in this case (other reasons). So i think if the tab (page) has been opened and is still open, there must be some ways that i can read the HTML when my web page is opened. The flow will be if there is Page1 opening, user opens mywebpage.html on the same Window, mywebpage.html finds there is Page1 opening, then grab the HTML source page and use it.

Thanks!

Edit:

This is the full story.

What I am planning to do is a FireFox plugin. And there is a Button (myPluginButton) on the tool bar.

If user click myPluginButton, the HTML code of the current page will be sent to the server, then server parse the HTML code and generate a report, a new tab then is opened to display this report.

My current approach is to read the HTML of current page using newTabBrowser.contentDocument and send it to server, then do the parsing on server side. But this approach creates extra traffic. The efficient way would be only the url of the current page is sent to the server, and we can 开发者_开发问答read HTML and parse it on the server side. However, the same domain policy does not allow me to do this easily.

So, my question is if it is possible to do when user click myPluginButton to open a new tab, this new tab loop all the opening tabs on the browser and reads the HTML contents of them then generate the report, since these tabs are still opening and the HTML contents must be saved on somewhere ( or i am wrong).

Thanks.


The browsers have a built in protection called same origin policy that prevent a page to read the content of other origin(domain, subdomain, port,...)

If you want to gain access to the current page you can use a bookmarklet.

You ask your users to add it in their bookmarks bar, and each time they want to use it, they don't open a tab but click on the bookmark.

This will load your script in the page, with all access to read the page content.

And oddly enough you can POST from this page to your domain, by posting a FORM to an IFRAME hosted on your domain. But you won't be able to read the response of the POST. You can use a setInterval with a JSONP call to your domain to know if the POST was successful.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜