How to set a frame for all pages

I am creating a website that hosts the website. For a better visit here, he has a page http://cocvidarbha.epizy.com/voting .

Now I want to visit http://cocvidarbha.epizy.com/voting/1.php . But the URL should only be considered as http://cocvidarbha.epizy.com/ .

I used frame source in index.php http://cocvidarbha.epizy.com/

+8
html php
source share
4 answers

It is rather a response on the client side.

Option 1:

What you can do is tell the browser to change the URL to something else you need (there may also be a nonexistent path). Please note: you cannot change your domain name.

So in your 1.php file add:

 <script> window.history.pushState("{data: 'pass data'}", "PageTitle", "/url"); </script> 

inside the head tag.

Option: 2

Another way I would recommend is using Ajax.

You can bind all of your <a href="/url"> so that when you click on it, it returns the data on this URL asynchronously without reloading the page.

So in the main index.php file add:

 <li> <a href="http://cocvidarbha.epizy.com/">Page 1</a> </li> <li> <a href="http://cocvidarbha.epizy.com/voting/1.php">Page 2</a> </li> <div id="content"> Content will be loaded here without any page reload or URL change </div> 

And then before </body> add:

 // Include jQuery <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha256-k2WSCIexGzOj3Euiig+TlR8gA0EmPjuc79OEeY5L45g=" crossorigin="anonymous"></script> <script> $(document).ready(function(e) { // Bind click event to all "<a>" tags $(document).on('click', 'a', function(){ var url = $(this).attr('href'); // Do Ajax Call to "href" clicked $.ajax({ url: url, type: "GET", success: function(data){ $('#content').html(data); } }) return false; }); }); </script> 
+5
source share

If you want only php voting only or part of your index page, you can always embed it in your index page. If the content is dynamic, this is one solution, as it avoids the use of frames (not supported in HTML5) / 301 redirects / etc ..

You can use php include to insert the file. The embedded file will be updated on the index page as a php file on the server. As stated in jagb below, it would be wise to use readfile when including a file; it will return an error message if the file does not exist.

eg:.

 @media (orientation: portrait) { body, .reorientMessage{ visibility: visible; } .mainContent{ visibility: hidden ; } } @media (orientation: landscape) { .reorientMessage{ visibility: hidden; } body,.mainContent{ visibility: visible ; } } 
 <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"> <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> </head> <body> <div class="reorientMessage">please reorient etc..</div> <div class="mainContent"><p>normal stuff here</p> <br><br></div> <?php include $_SERVER['DOCUMENT_ROOT'] . '/path/1.php';?> </body> </html> 

[html above, taken from the source output from your index page - 1.php embedded]

file_get_contents php function will read the contents of the 1.php file and return the contents as a string.

You can embed it in a similar way using

 <?php $1 = file_get_contents('./yourserverpath/1.php'); echo $1; ?> 

where $ 1 is your variable containing the contents of the file (and subsequently spits them out! :))

so your final index page code will look like this:

 @media (orientation: portrait) { body, .reorientMessage { visibility: visible; } .mainContent { visibility: hidden; } } @media (orientation: landscape) { .reorientMessage { visibility: hidden; } body, .mainContent { visibility: visible; } } 
 <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"> <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> </head> <body> <div class="reorientMessage">please reorient etc..</div> <div class="mainContent"> <p>normal stuff here</p> <br><br></div> <?php $1 = file_get_contents('http://cocvidarbha.epizy.com/voting/1.php'); //I'm putting in the url cos i don't know your path but use the suggested //method - $1 = file_get_contents('./yourserverpath/1.php'); echo $1; ?> </body> </html> 
+3
source share

If you need to redirect from the default landing page ( index.php ) to the desired page ( 1.php ) by adding the following lines to your index.php code,

 header("location:voting/1.php"); exit; 

If you want to use the frame tag only without redirecting to display the URL, change the value of the src attribute to vote / 1.php

+2
source share

Try using the following example where I have a link and an iframe on my web page.

 <a id="myLInk" href="ClickMe.html" target="myIFrame"> Click Me </a> 

Here target="myIFrame" will make the link open in the IFrame with Id "myIFrame".

And this is my iframe.

 <iframe name="myIFrame" src="index.html" align="top" height="500" width="95%" hspace="10" vspace="10" align="middle"> If you can see this, your browser does not support iframes! </iframe> 

Now, when you click on the link above with the identifier "myLInk", the link source (for example, ClickMe.html) will be loaded into the iframe. This way you can load as many links as possible without having to go to a new page. And that will remain the same URL.

+1
source share

All Articles