Dirrect way to get content of current open page into main.js file in FireFox add-on sdk - firefox-addon-sdk

I have one problem with add-on Firefox sdk. I'm searching a way to get content of current working page into main.js file. The application is based on widget that open popup when is clicked. I have one idea. To inject content script into open with sdk/page-worker and this content script using port API (self.port.emit) to trigger event and pass document.body.innerHTML. Like this:
self.port.emit("getCurrentPageHtml", document.body.innerHTML);
And into main.js file:
popupName.port.on("getCurrentPageHtml", function (receivedHtml) {
// handle received html
});
But will be very good idea if there is some direct API and avoid this communication.
I would appreciate any advice and tips.
Best regards.

I answer my own question for the second time today. Pity. Apparently there is no direct way to do this. So we can listen for panel event with popuVar.port.on. After this we can use:
// must be required tab api
// https://developer.mozilla.org/en-US/Add-ons/SDK/High-Level_APIs/tabs
tabs.activeTab.url
and use page-worker on this url https://developer.mozilla.org/en-US/Add-ons/SDK/High-Level_APIs/page-worker. After this content script of this page worker will trigger event to get html of page. Another option is just made request to url of current page.

Related

Web Page Redirect and Block Return

I'm using a simple (Meta) timed redirect on a web page. The viewer may wait the allotted time or click on a link to leave the page. I would like to block the viewer's ability to return to the original page after leaving it.
I've been cautioned about using Meta scripts due to the possibility of search engine rejection- true or not, I haven't a clue.
If possible, I would like to avoid Java or the use of cookies. Nonetheless, if Java is the best or only solution, I am open to it.
Your thoughts and guidance are greatly appreciated.
Thanks.
You can try something like this:
<script>
function preventBack(){window.history.forward();}
setTimeout("preventBack()", 0);
window.onunload=function(){null};
</script>
You can place that code on the page that you don't want the user accessing using the back button in the head section. But, it is not recommended since it might annoy your users.
This post explains things in a bit more detail from multiple users.

How to find if web page got appended using chrome extension

I am new to chrome extension and I am trying to find whether page content got appended.
For E.g. in Facebook, we can see the content will appended automatically when the user scroll down the page.
I have the following code in background.js
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
alert("page is appending....");
});
The above code is expected to fire when the page got updated. But, I am seeing that it is getting called only for few times. Not always.
Or Am I making any mistake here ?
My requirement is, whenever the web page appended in facebook, I have to do get the page content and obtain few string from the same.
Thanks in advance.
Your onUpdated event is in the chrome.tabs namespace on purpose, it listens the updates of tab's general attributes like: the tab pinned, the favicon changed, the URL changed, see the documentation (also check the update() method). So this way is not workable. Instead listen the DOM tree change with DOMSubtreeModified event or MutationObserver.

zend framework redirector->gotoUrl() with target=_blank

On submitting a form I want to sent my visitor to an external url to do something but hope he will continue browsing my site afterwards. In html I would give him that opportunity with href="http://www.example.com" target="_blank".
But I cannot find how to do that when I do:
$this->_helper->redirector->gotoUrl('http://www.example.com');
within my controller action. Nothing found in Google, documentation nor SO. Is it just not possible?
Not possible. You can't tell the browser what to do in this scenario.
You can achieve that effect with the help of Javascript:
submit the form
on success, open a new tab with the external page with JS
redirect to a new location within your app on the old tab
It is possible now:
$link = new PTA_Link();
$link->setTarget('_blank');

Can't add external script into gwt widget

I am trying to add google gadget into FlowPanel(or HTMLPanel), but after a host page is loaded it navigates away from my page and shows gadget in a new page, if i click browser's back button it loads host page and again navigates away to new page to show the gadget.
Here is the code:
String code="here_goes_scrip_tag_for_gadget";
flowPanel.add(new HTML(SafeHtmlUtils.fromTrustedString(code)));
What am i doing wrong, please help.
UPDATE
The above code to load script was wrong, i've modified it as following:
FlowPanel gadgetContainer = new FlowPanel();
Element script = Document.get().createScriptElement();
script.setAttribute("type", "text/javascript");
script.setAttribute("src", "http://www.gmodules.com/ig/ifr?url=http://digg.com/goog/ig.xml&up_user=&up_thumbnail=1&up_filter=0&up_num=5&up_type=popular&up_refresh=0&up_tab=0&up_offset=0&up_pagination=0&up_business=true&up_entertainment=true&up_gaming=true&up_lifestyle=true&up_offbeat=true&up_politics=true&up_science=true&up_sports=true&up_technology=true&up_world_news=true&synd=open&w=320&h=200&title=Digg&border=%23ffffff%7C3px%2C1px+solid+%23999999&output=js");
gadgetContainer.getElement().appendChild(script);
But it still doesn't work.
For solving this problem in general, check out the com.google.gwt.core.client.ScriptInjector class - it has two methods that allow you to inject scripts into the page in a cross browser way. The way you are attempting to inject the script content won't work cross browser.
Looking specifically at your gadget case, I'm guessing that the script you are loading has code in it to prevent it from being loaded into another page. Have you tried to use a plain html page that references that script tag? If the same thing happens, see if you can see where in the script file the page reassigns window.location.

titanium webview - go to default browser when clicking links

in titanium, i'm using the webview to display a wordpress blog page, that is already formatted for mobile browser. instead of writing my own interface, this works as a good work around. the apps sole focus isn't the browser.
but my issue lies, when the user clicks a link outside of the initial displayed domain. i only want the main domain to be displayed in the apps browser. if any other link is clicked, that takes the user outside of that domain, i want to have it open in the phones default browser.
can anyone point me in a direction for this. i tried adding a listener to try and catch link clicks, however, i've been unsuccessful.
thanks
in this blog posting I show how to find links in a webpage and change the link behavior. Using the same method, you can intercept the links and redirect to opening the URL in the devices default browser
One solution would be to catch the onclick() Event by Javascript inside the WebView (your blog code) and handle this by a custom handler. Maybe you can inject the javascript event handler code into the running WebView through Titanium.
Another solution is to make your blogposts readable for app technology and create a new data interface. This is the way I would do. For that I would use some kind of JSON data format and a simple REST Interface to get the data.
I don't think bove solutions are that simple. If you want an app with "great feeling", you'll have to handle the events by your own. Maybe Phonegap would be a better solution four your problem. But there you will still need a kind of REST/JSON interface for your blog data. The idea behind an app is, that the main code is in your app and you get the content from a remote source. This way you'll get an advantage compared to a simple browser optimized site.