Popup Window on PHP Table - javascript

Hello everyone I am a newbie and a student and there is a code in PHP that I want to have on my PHP.
So what I want is if I click the URL it should popup a new window. I know how to do it in a button but I have no idea how to do it using echo.
PS: THIS IS THE CODE I WANT TO REPLACE
echo"<td><a href=update.php?primary=".$row['ID']."'>Update</a>";
PS: Please correct me / Teach me.
PS: I am now able to open it in a new window but the problem is I am not able to get the primary.
Here is my code: echo"<a href=update.php target=popup onclick=window.open('update.php','popup','width=500,height=500');return false;?primary=".$row['ID'].">Update ";

Please do research before asking a question.
Ether way, I suggest over all you'd visit a site called W3Schools, its very basic, but provides with pretty useful stuff.
In this case you need to add the attribute "target", to _blank If I am not mistaken. You can read about what kind of target attribute options you can do hare: https://www.w3schools.com/tags/att_a_target.asp
Since you are a new contributor, I suggest looking trough that site at minimal before going with a post.
Added the solution with explanation.
echo"<td><a href=update.php?primary=".$row['ID']."'>Update</a>";
Change it to:
echo"<td><a target='_blank' href='update.php?primary=".$row['ID']."'>Update</a>";
By the way, you forgotten to add a qoute on your href attribute, this might've been causing some problems.
The target is a "<a>" tag attribute, its just html, echo from PHP side just acts as a renderer from php files. So whatever you put in your echo will render with HTML. Its important to add <head> and <html> tags so it would render like a full HTML document, just having php tags. It is wise to separate these things to make a proper framework A.K.A - using template system and leaving PHP parts to be only calculations from endpoint (Server side). I'd advise you to learn some sort of framework like Symfony based frameworks (Laravel for example). It will be a bigger hustle to learn, but you would learn it the right way and would know way more about these things from that.

echo"<td><a target=_blank href='update.php?primary="'.$row['ID'].'"'>Update</a>";
target=_blank is what you want to open a new window from a link href.

Related

How would I dynamically clone a site and apply custom css to it?

So my school has a "portal"; a site with heaps of resources for the students and teachers. Only downside is that it is really, really badly designed and runs on HTML4. I have some decent web design skills and I want to try and improve it. I have asked if I could directly edit it and I was very quickly shut down. So how would I go about cloning the site while applying custom CSS?
While doing an iframe seems like a great idea to start with, it is quickly stopped by CORS. You can't apply custom CSS to an iframe with an origin of a different domain.
I could just download the site's source code and write custom CSS for that, but that way it won't update when new content is updated.
I am happy to play around with django/flask if needed since I have a lot of experience with python and if it works, I can create a downloadable app using react or something.
Anyone got any ideas?
Just go to the website you want to clone
Right click
Inspect element
Copy the whole html code
Paste it to you code editor
Add a tag a <style>
Enter Css to customize it with respect to the tags of the html code
You are done!!!
Happy coding :)
If I wanted to clone someone else's terribly built website, I would use PHP and DOM parsing.
https://codingreflections.com/php-parse-html/
In a perfect world, their code will follow some kind of pattern and, using the DOM parser, you'd be able to pick out their navigation and internal href links, and rewrite them to point to your site like http://terriblewebsite.com/aboutus.phtml => http://imborrowingyourwebsite.com?page=http://terriblewebsite.com/aboutus.phtml.
I would write all my css in a single file, remove their <link tags and insert my own css file links -- but use their classes as much as possible.
Your index.php file would basically be (this is a rough sketch)
<?php
$url = "http://terriblewebsite.com";
if ($_GET['url']) $url = urldecode($_GET['url']);
$dom = new DomDocument();
# $dom->loadHTML($url);
// change nav
$nav = $dom->getElementById('navbar'); //DOMElement
$nav_links = $nav->getElementsByTagName('a'); //DOMNodeList
foreach($nav_links as $item) {
$item->setAttribute('href', 'http://imborrowingyourwebsite.com?page='.$item->getAttribute('href'));
}
// ... other transformations...
// finally
echo $dom->saveHTML();
?>

manipulating tinymce in Wordpress

I need to be able to extract, manipulate and update the text in wordpress's tinymce #content textbox.The code is coded in a wordpress plugin.
The below post helps but i am unable to comment or contact the original creator to ask him further questions. Having 1 points I cant practically do anything except ask questions. Let me know if i am doing this wrong.
Basically the code from this link is what i need to manipulate or edit the content in wordpress tinymce editor.
Manipulating TinyMCE content with jQuery
But the code seems to be overly simplified.
so my question is:
Do i need to include jquery
Do i need to include the tinymce js or class? is it in wordpress itself?
The code seems to be half javascript half php? Is the code suppose to be coded in a .js file?
do i need to put php tags here?
// make it into a jQuery object
var $content = $(content);
// manipulate the jquery object using jquery
$content = $content.remove('a');
Thanks.
hi I have figured it out after a bit more researching.
At first I was working with php to manipulate data after it is saved. But then i went on to wanting to manipulate the text before it was saved like underlining certain text based on a list in the database. So I needed to move on to javascript because i was editing the text before it was submitted or a page reload which i didn't wrap my head around yet.
So next i just coded the changes into javascript and built a button to call the process.
and seems i didn't need to include the tinymce class because probably the header of the editor page has already included it.

Inserting Text Into HTML

What I Want: Very simply I have a C program that generates a variable periodically, I want to be able to display this value on a website.
Restrictions: The webpage is HTML, php does not work, javascript does [I have tried a few javascript solutions but they have all been long, tedious and in the end ineffective] I want it to be able to format the text so that it matches the rest of the webpage. Above all I'd really like to find something simple that works.
Freedoms: I can output the variable from my C program to just about any file type and content that I want, the file is hosted so is available locally to the server or online for the client.
Preferred Solutions: I am currently playing around with the object and iframe tags native to html. They give a nice simple input:
<object height=20 width=75 type='text/plain' border=0 data="URL/filename.txt"></object>
inserts the contents of my file, but it can't be formatted so I am stuck with 12pt Courier font which is not acceptable. Using
<iframe seamless height=20 width=75 scrolling='no' src="URL/filename.htm"></iframe>
and adding my desired font/colour/size etc to the htm file gets me the right text style, but htm has a large amount of white padding around it which I can't seem to get rid of so I have to make my iframe quite large for the text to be displayed, but then it doesn't fit smoothly with other text.
So anyone that can answer one of four questions:
How to remove excess padding from htm
How to format the style of a html object
Is there anything in Java as simple as the php [so apparently it doesn't show php code even when you quote it as code. But basically using echo and get_file_contents to insert the contents of a txt file into a html page]
Propose an alternate solution
Padding and style can be handled by css.
By java I assume you mean javascript - google-ing will help you. Without details of what your server is running and what is dispatching your pages we can't give you an exact answer. You might want something with ajax to keep it updating in the background.
Try googling your question, you'd be surprised how often this helps.
I'm not sure what you're trying to do once you get the variable into your web page, but I think something like the following could be useful.
Create a hidden div on your page
Have your C application write the variable to some file
Use jquery to execute an ajax call to pull that value into the div ( or whatever other container you want to use
using some type of timer, execute the ajax call every X period of time, which will then get your up to date variable
on your main page, have another timer that will then come in to that container, grab your value and then you are free to do what you want with it.
This is all off the top of my head without knowing much about what you're trying to accomplish. If you provide some further details we may be able to help you a little more.
You need AJAX... that's just a fancy buzz-word. It means you can tell JavaScript can get a file from the server without reloading the page and you can insert data from that file into your HTML.
AJAX is made much simpler by using a JavaScript library like jQuery, but it can be done without jQuery. There's a pretty decent Getting Started tutorial at Mozilla Developer Network if you want to do it the hard way, but I really recommend jQuery.
As far as formatting... any formatting... you need to use CSS. Just about everything about the appearance of anything on a web page is controlled by CSS. MDN has a Learn CSS section, too.
load jquery on you main html file
put a div with some id (example id="newvalue")
make you c program to write the output in a file (for example value.html)
on main html page header, after jquery include code add some javascript like
$( document ).ready(function() {
$("#newvalue").load('yoursiteurl/value.html');
});

Html/Javascript - How to make an html link display a url, and have it actually be redirected to a javascript function?

I have an html page, and I need a link to show that the user would be going to 'example.html', when really, the link goes to 'javascipt:ajaxLoad(example.html);'.
I tried this:
Example
But it didn't work. Any help? I already asked the webmasters stackexchange, and they told me that this would be a javascript programming question. Not an html question.
Example
By returning false you prevent the default action. And this way the links will still work when javascript is disabled, but then you don't get the AJAX functionality.
Just point the href at the actual file. The javascript onclick will take precedence - as long as you take care to disable the actual click effect by doing a "return false" or similar, the status bar will show 'example.html' and not the javascript url.
As well, note that it should be javascript:... (you're missing an r). The onwhatever attributes are already assumed to be javascript, so you could just say onclick="ajaxLoad(...) anyways.
Look, I'm not sure if I got exactly what you're asking about here, but the following fix often works with me. Just change the double-quotes to single-quotes, and put double-quotes around the example.html part
<a href="example" onclick='javascipt:ajaxLoad("example.html");'>Example</a>

making un-visible a specific part of url generated by javascript + codeigniter

http://www.blabla.com/our_work/client/client-name#/uploads/18.jpg
I use CodeIgniter, and this is the url I have. I use a gallery script at the page, and it generates #/uploads/18.jpg such thing at url :( is there any way to make it unvisible or sth . maybe with htaccess. i dont know.
i dont want to spend an another day finding an another gallery script, im already out of deadline :(
appreciate helps...
Just leave it there. What's the harm? Really. You are on a deadline, and are wasting time trying to remove a #tag from the url.
Can we have a look at the gallery script? perhaps you could edit something there to make it work. That's what I always do with the scripts I use to make them work with CI.
I'm afraid that's how it's supposed to work. the '#' part is an HTML anchor that the script uses to do the switching as far as I know. You might to look for a different script.
you can try to play with window.location in JS erasing the string after hash, but I doubt that would make some sense.

Categories

Resources