I want to restrict the browser not to open a page multiple times. If a page is already opened then same page should not be opened in new tab. This is because I am using a weighing scale exe file which loads wight value to URL localhost\weight\{value}. I am getting that value in my blade addweight.blade.php and using it as input in form. So every time the exe load it calls localhost\weight\{value} and it opens a new tab. It makes user to feel annoyed by opening same page in different tab. Please help me out with this.
you can try using local storage.
Window.onload=function(){
if(localStorage.getItem('tab')===1){
window.close();
}else{
localStorage.setItem("tab",1);
}
}
Window.onbeforeunload=function(){
localStorage.setItem("tab",0);
}
Related
I'm looking for a method so that by clicking on a link in the current window of my web page I will generate a tab within the current window instead of opening a new browser window, and that this new tab has the option of being able to close (similar to an excel file where when creating a new sheet a tab is added at the bottom but have an x to close the tab). It must be flexible to create an infinite number of tabs so that depending on what is needed, the user can have several pages open at the same time and close them when they are no longer needed. I'm not sure if I should use tabs or iframes. what should i do or use? regards
PHP is server side but you can still kind open in a new tab/window.
It mostly depends on how the user configures their browser but you could just add target="_blank" to all of your <a> tags. For instance this link:
FollowTheHrefToAnExample
Alternatively you can use javascript:
window.open(destinationURL, '_blank').focus();
During web coding, We will check the page quite often. To accelerate our speed, We will open two page, one for change, one for compare.
Is there a way to clone an page completely? I mean not the usual way that open current page's URL in an new tab. I wish that eg. if Page A open a tab via js and load data via ajax, then the clone Page B should open tabe and load data too.
If can, it will be totally amazing. Thanks.
In this case you can use Blob api of javascript
How Can i know using PHP, Whether the current request is from a popup window or from a normal browser window ?
--
Thank you
if you open popup yourself you can open window with query string like this:
window.open("page.php?popup=1");
then you can check this query string in php like this:
if(isset($_GET['popup'])){
echo 'popup window';
}else{
echo 'normal window';
}
You cannot do it with PHP.
You may want to use `$_SERVER['HTTP_REFERER'] to determine how the user reached the page to determine if it's a popup window.
If you have the option of using JQuery then you can use $(window).height(); to determine the size of the window.
With raw JS things get a little more complicated: http://andylangton.co.uk/blog/development/get-viewport-size-width-and-height-javascript
PHP is server side, browser window are client side. there is no way to know this using only PHP... you need a client side language that can tell the difference, and pass it through to your PHP script.
But as was already said in the comments, there is no inherent difference between a popup and a 'normal' browser window... just as there is no difference between 2 instances of a browser and 2 tabs in the same browser window...
How can I determine if a page is opening in an overlay or in a browser window?
To be more exact, it's download page behavior from GitHub: if you click on the Downloads button from this page, it will open a facebox overlay. However, if you copy the address from the respective link and paste it into a new tab, it will open as a new page.
So how do you check to see where is the page opening (assuming PHP)?
Edit:
This was what I was looking for.
I think you need to do the checking on the client using JavaScript and PHP is not going to help you on this one. As far as I can tell from your post you need figure out how the page is loaded. Probably it is an iframe or such. Of that you must be able to retrieve the loaded address.
I don't know why you would want to check that, but as you can see the link has an id="download_button". And in the bundle_hithub.js file the download_button is associated with the popup event. I don't know how exactyly, it's hard to read those single-line compressed JS files.
if the page that is going to be loaded has the following script
<script type="text/javascript">
window.location = "http://page-loads";
</script>
it won't run when loaded through an ajax call (since the page will most likely be appended with an innerHTML way resulting in the script being appended in the document, but not ran)
but when opened solely in the browser window - the script will run taking the user away to the desired destination!
I have 100 links for example, in a file. The idea is to loading to a php page, it loads the links file, it reads the first line and gets the first link. Then it opens it in a new window of browser, after 5 seconds the page refreshes itself and it gets the second link from the file and opens it in a new window again.
Now, I can do the whole thing by php, But I don't know how to open the link in a new window automatically without any click. and I guess it might be possible through JS.
Thanks for help :)
window.open('http://www.someurl.com','NameOfWindow');
There are also attributes you can keep specify to have more control. See http://www.pageresource.com/jscript/jwinopen.htm